from flask import Blueprint,jsonify, request
from main.BSL.noticeBSL import *
from main.BSL import userBSL
from main.utils import InterfaceHelper,RequestHelper
notice = Blueprint('notice', __name__)


@notice.route('/notice/add', methods=["POST"])
def add_notice():
    res = {}
    dic = RequestHelper.formToDict(request)
    notice = JSONHelper.dictToObj(dic, Notice)
    try:
        insert(notice)
        res['status'] = 1
    except:
        res['status'] = 0
    return jsonify(res)


@notice.route('/notice', methods=["GET"])
def get_notice():
    res = {}
    dic = RequestHelper.formToDict(request)
    try:
        data = []
        for i in query_user_id_is_notice(dic['user_id'], dic['is_notice']):
            data.append(i.to_json())

        res['notices'] = data
        if data:
            res['status'] = 1
        else:
            res['status'] = 0
    except:
        res['status'] = 0
    return jsonify(res)


